CC = g++
SOURCES = $(wildcard *.cpp)  
OBJS = $(patsubst %.cpp,%.o, $(SOURCES))  

CBUILD_PATH = ./build/ 
MAKE_PUBLIC = ../public/

PATH_SHARE = ../thread/build/
export PATH_SHARE

CFLAGS = -std=c++11	-lpthread -g
export CFLAGS

define cmd_init
if [ ! -d $(CBUILD_PATH) ]; then \
    mkdir -p $(CBUILD_PATH); \
fi
endef

define cmd_finsh
	mv *.o $(CBUILD_PATH)
	cp finsh.mk ./build/makefile
endef

all:init $(OBJS)

$(OBJS):%.o:%.cpp
	g++ -c -fPIC $(SOURCES) $(CFLAGS)
	$(cmd_finsh)
	$(MAKE) -C $(CBUILD_PATH)
	@echo 完成!
	
init:
	$(cmd_init)
	@echo 准备初始化其他makefile！
	$(MAKE) share -C $(MAKE_PUBLIC)

cleanall:clean
	@echo 清除所有!
	rm -rf ./build/
	$(MAKE) cleanall -C $(MAKE_PUBLIC)

clean:
	rm -f *.o *.d